using System;
using UnityEngine;
using UnityEngine.UI;

public class Weather : MonoBehaviour
{
	[Serializable]
	public struct Element
	{
		public Sprite day;

		public Sprite night;

		public Image targetImage;

		public SpriteRenderer target;
	}

	[SerializeField]
	private Element[] elements;

	private void Start()
	{
        AdManager1.instance.InitData();

        LoadWeather();
	}

	public void LoadWeather()
	{
		int hours = DateTime.Now.TimeOfDay.Hours;
		if (hours < 6 || (hours >= 18 && hours <= 24))
		{
			for (int i = 0; i < elements.Length; i++)
			{
				if (elements[i].target != null)
				{
					elements[i].target.sprite = elements[i].night;
				}
				if (elements[i].targetImage != null)
				{
					elements[i].targetImage.sprite = elements[i].night;
				}
			}
		}
		else
		{
			if (hours < 6 || hours >= 18)
			{
				return;
			}
			for (int j = 0; j < elements.Length; j++)
			{
				if (elements[j].target != null)
				{
					elements[j].target.sprite = elements[j].day;
				}
				if (elements[j].targetImage != null)
				{
					elements[j].targetImage.sprite = elements[j].day;
				}
			}
		}
	}

	private void OnApplicationPause(bool paused)
	{
		if (!paused)
		{
			LoadWeather();
		}
	}
}
